package sixkey.domain.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

/**
 * ClassName:User
 * Package:sixkey.entity
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/5/19 - 23:20
 * @Version:v1.0
 */

/**
 * 系统用户类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("sys_user") //对应数据库的表
@Accessors(chain = true) //可以链式编写
public class User implements Serializable {

    @TableId // 主键
    private Long id;

    @NotBlank(message = "用户名不能为空")
    @Length(min = 1, max = 10,message = "用户名长度在1-10个字符内")
    private String username;

    @NotBlank(message = "密码不能为空")
    @Length(min = 6,max = 20,message = "密码长度在6-20个字符内")
    private String password;

    @JsonIgnore //忽略前端传过来的值
    private String salt = UUID.randomUUID().toString().replaceAll("-","");

    @JsonIgnore
    private Long status;

    @NotNull(message = "年龄不能为空")
    @Min(value = 0, message = "年龄最小为0岁")
    @Max(value = 100, message = "年龄最大为100岁")
    private Integer age;

    @NotBlank(message = "性别不能为空")
    @Length(max = 1,message = "性别长度最大为1个字符")
    private String sex;

    @NotBlank(message = "电话号码不能为空")
    @Min(value = 11, message = "电话号码为11位")
    @Max(value = 11, message = "电话号码为11位")
    private String phone;

    @TableLogic
    @JsonIgnore
    private Integer deleted; //逻辑删除

    @TableField(fill = FieldFill.INSERT) //插入时自动填充
    private Date createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE) //修改时自动填充
    private Date updateTime;
}
